import Vue from 'vue'

import router from './router/index'
import store from './store/index'
import axios from 'axios';
Vue.prototype.$axios=axios;


import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
axios.defaults.baseURL = 'https://api.mxzhuawawa.com'

Vue.prototype.URL_PREFIX = 'https://api.mxzhuawawa.com'

require('!style-loader!css-loader!less-loader!./assets/css/swiper.min.css')
require('!style-loader!css-loader!less-loader!./assets/css/animate.css')
require('!style-loader!css-loader!less-loader!./assets/css/main.less?v=1')




var vm=new Vue({
  router,
  store,
  data:{
  	host:'https://api.mxzhuawawa.com',
  },
  template: `
  		<div>
  			<transition name="fade" mode="out-in">
  				<router-view></router-view>
  			</transition>
  		</div>
  `,
  created(){
      this.$store.commit("isIphoneX",this.isIphoneX())
      var inviteid=this.getQueryString("inviteid")
      if(!inviteid){inviteid=0;}
      this.$jsonp(`https://wanba.mxzhuawawa.com/wanba_login.php`,
          {
            "inviteid":inviteid,
            "openkey":this.$store.state.openkey,
            "openid":this.$store.state.openid,
            "platform":this.$store.state.platform
          }
        ).then((response) => {
                this.$store.commit("getUserinfo",response.data);
                this.$store.commit("getRegister",response.data.is_register == 1 ? true : false);
                window.mqq.ui.setOnShareHandler(function(type){
                  window.mqq.ui.shareMessage({
                      title: '梦想抓娃娃',
                      desc: '快来抓一把娃娃吧！',
                      share_type: type,
                      share_url: "https://h5.qzone.qq.com/app/open/1106718756/home?_proxy=1&inviteid=" + response.data.uid,
                      image_url: window.OPEN_DATA.appicon,
                      back: true
                  },function(result){
                      if(result && result.retCode ==0){
                          window.mqq.ui.showTips({
                              text: "分享成功",
                              iconMode: 2
                          })
                      }else{
                          window.mqq.ui.showTips({
                              text: "分享取消",
                              iconMode: 2
                          })
                      }
                  })
              })
        }).catch((response)=>{
            alert("err1"+JSON.stringify(response))
        })
  },
  methods:{
    getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    },
    isIphoneX(){
      return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375)
    }
  }
}).$mount("#app")

Vue.directive("focus",{
    inserted: function (el) {
      el.focus()
    }
})
